package com.gestordeavisos;

import java.io.IOException;
import java.util.logging.Logger;
import java.lang.Long;
import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class EliminarAvisoServlet extends HttpServlet {
	
	private static final Logger log = Logger.getLogger(EliminarAvisoServlet.class.getName());
    
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
	    String key = req.getParameter("key");
	    if (key == null) {
	      resp.getWriter().println("No existe key.");
	    }
	    else
	    {
	    PersistenceManager pm = PMF.get().getPersistenceManager();
	    try {
	      Aviso a = pm.getObjectById(Aviso.class, Long.valueOf(key));
	      pm.deletePersistent(a);
	    } finally {
	      if (pm.currentTransaction().isActive()) {
	        pm.currentTransaction().rollback();
	      }
	      pm.close();
	    }
	    }
	    resp.sendRedirect("/gestordeavisos.jsp");
    }

}
